package com.classic.adapter;

import android.support.annotation.NonNull;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;

import com.classic.base.BaseFragment;
import com.classic.fragment.DetailsListFragment;

import java.util.ArrayList;
import java.util.List;

public class ListDetailsAdapter extends FragmentPagerAdapter {
    private List<BaseFragment> fragments = new ArrayList<>();

    public ListDetailsAdapter(FragmentManager childFragmentManager,String url) {
        super(childFragmentManager);
        String[] split = url.split("/");
        int i = 0;
        if (split.length > 0) {
            String s1 = split[split.length - 1];
            String s2 = s1.split("\\.")[0];
            i = Integer.parseInt(s2);
        }
        String mUrl = "";
        for (int c = 0;c<split.length-1;c++){
            mUrl = mUrl+split[c]+"/";
        }
        for (int b = 0; b < 2000; b++) {
            fragments.add(DetailsListFragment.getFragment(mUrl+(i+b)+".html"));
        }
    }
    public ListDetailsAdapter(FragmentManager childFragmentManager) {
        super(childFragmentManager);
        for (int b = 0; b < 2000; b++) {
            fragments.add(DetailsListFragment.getFragment(""));
        }
    }

    @Override
    public long getItemId(int position) {
        return fragments.get(position).hashCode();
    }


    @Override
    public int getItemPosition(@NonNull Object object) {
        return super.getItemPosition(object);
    }


    @Override
    public Fragment getItem(int position) {
        return fragments.get(position);
    }

    @Override
    public int getCount() {
        return fragments.size();
    }

}
